//index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dateIndex: 0,
    option: null,
    dataList: [
      [{
          value: 9.6,
          name: 'PM2.5'
        },
        {
          value: 7.7,
          name: 'PM10'
        },
        {
          value: 4.5,
          name: 'SO2'
        },
        {
          value: 9.6,
          name: 'NO2'
        },
        {
          value: 15.1,
          name: 'CO'
        },
        {
          value: 18.0,
          name: 'O3'
        },
      ],
      [{
          value: 9.6,
          name: 'PM2.5'
        },
        {
          value: 17.7,
          name: 'PM10'
        },
        {
          value: 24.5,
          name: 'SO2'
        },
        {
          value: 39.6,
          name: 'NO2'
        },
        {
          value: 15.1,
          name: 'CO'
        },
        {
          value: 18.0,
          name: 'O3'
        },
      ],
      [{
          value: 49.6,
          name: 'PM2.5'
        },
        {
          value: 127.7,
          name: 'PM10'
        },
        {
          value: 24.5,
          name: 'SO2'
        },
        {
          value: 329.6,
          name: 'NO2'
        },
        {
          value: 15.1,
          name: 'CO'
        },
        {
          value: 18.0,
          name: 'O3'
        },
      ],
      [{
          value: 491.6,
          name: 'PM2.5'
        },
        {
          value: 127.7,
          name: 'PM10'
        },
        {
          value: 241.5,
          name: 'SO2'
        },
        {
          value: 329.6,
          name: 'NO2'
        },
        {
          value: 151.1,
          name: 'CO'
        },
        {
          value: 181.0,
          name: 'O3'
        },
      ],
    ]
  },

  changeChartTime(e) {
    let index = e.currentTarget.dataset.item
    this.setChart(this.data.dataList[index])
    this.setData({
      dateIndex: index
    })
  },
  setChart(mdata) {
    this.setData({
      option: {
        legend: {
          top: 'bottom',
          data: []
        },
        tooltip: {
          trigger: 'item',
        },
        title: {
          text: "分担率",
          left: "center",
          top: "50%",
          textStyle: {
            fontSize: 18,
            fontFamily: 'Microsoft YaHei',
            fontWeight: 400,
            color: '#AAAAAA',
            align: "center",
          }
        },
        graphic: {
          type: "text",
          left: "center",
          top: "40%",
          style: {
            text: "综指",
            textAlign: "center",
            fill: "#333",
            fontSize: 20,
            fontWeight: 700
          }
        },
        series: [{
          name: '综指分担率',
          type: 'pie',
          radius: ['40%', '70%'],
          emphasis: {
            label: {
              show: true,
              fontSize: '40',
              fontWeight: 'bold'
            }
          },
          data: mdata,
        }]
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '综指分担率',
    })
    this.setChart(this.data.dataList[0])
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})